package com.zhengx.blehelper;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattService;

import java.util.List;


/**
 * name：BleCallback
 * class: 蓝牙回调管理
 * author: zhengx
 * create_time: 2018/10/29
 */
public class BleCallback {

    /**
     * 外部接口
     */
    public interface OnBleClientChangeListener {

        /**
         * 蓝牙连接
         */
        void onConnected(final BluetoothLeClient client);

        /**
         * 连接超时（目前没使用）
         */
        void onConnectTimeout(final BluetoothLeClient client);

        /**
         * 重连回调
         * @param count 正在进行第 x 次重连
         */
        void onReConnect(final BluetoothLeClient client, int count);

        /**
         * 断开连接或连接失败
         */
        void onDisconnected(final BluetoothLeClient client);

        /**
         * 服务发现
         * @param services
         */
        void onServiceDiscovered(final BluetoothLeClient client, final List<BluetoothGattService> services);

        /**
         * 读写通知的特征值设定完成
         */
        void onGattCharacteristicSet(final BluetoothLeClient client);

        /**
         * 写入回调
         * @param writeData
         */
        void onWriteValue(final BluetoothLeClient client, final byte[] writeData);

        /**
         * 读取信息回调
         * @param msgType 数据类型
         * @param source
         */
        void onRead(final BluetoothLeClient client, final BluetoothLeClient.MsgType msgType, final byte[] source);

        /**
         * 读取信号回调
         * @param rssi 信号值
         * @param success 是否读取信号成功
         */
        void onReadRemoteRssi(final BluetoothLeClient client, int rssi, boolean success);

    }

    /**
     * 蓝牙开关状态回调
     */
    public interface OnBluetoothStatusListener {
        void onStatusChange(boolean isEnable);
    }

    protected interface OnReadMsgCallback {
        void onRead(byte[] msg);
    }

    public interface OnScanStateChangedCallback {
        void onStartScan();
        void onDiscoveryDevice(final BluetoothDevice bluetoothDevice);
        void onFindSpecifiedDevice(final BluetoothDevice bluetoothDevice);
        void onFinished(boolean isCanceled, final List<BluetoothDevice> devices);
        void onTimeOut();
    }

    /**
     * 蓝牙状态回调接口, 内部使用
     */
    protected interface BleGattCallback {
        void onConnected(final BluetoothLeClient client);
        void onConnectTimeout(final BluetoothLeClient client);
        void onDisconnected(final BluetoothLeClient client);

        void onReConnect(final BluetoothLeClient client, int count);

        void onServiceDiscovered(final BluetoothLeClient client, final List<BluetoothGattService> services);
        void onGattCharacteristicSet(final BluetoothLeClient client);

        void onWriteValue(final BluetoothLeClient client, final byte[] writeData);

        void onRead(final BluetoothLeClient client, final BluetoothLeClient.MsgType msgType, final byte[] source);

        void onReadRemoteRssi(final BluetoothLeClient client, int rssi, boolean success);

    }
}
